﻿using System.Windows;
using AnthStat.WPF.Applications;

namespace AnthStat.WPF.Presentation
{
    /// <summary>
    /// Interaction logic for AnthStatWindow.xaml
    /// </summary>
    public partial class AnthStatWindow : Window
    {
        public AnthStatWindow()
        {
            InitializeComponent();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            // TODO: Look for a better way of handling this

            FileScreenViewModel vm = this.DataContext as FileScreenViewModel;

            if(vm != null && vm.CurrentProject != null) 
            {
                MessageBoxResult result = System.Windows.MessageBox.Show("Do you want to save changes before closing?", "Save changes?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                if (result == MessageBoxResult.Cancel)
                {
                    e.Cancel = true;
                }
                else
                {
                    if (result == MessageBoxResult.Yes)
                    {
                        vm.CloseAndSaveProjectCommand.Execute(null);
                    }

                    Properties.Settings.Default.Save();
                }
            }
        }

        private void btnOptions_Click(object sender, RoutedEventArgs e)
        {
            // TODO: Might be able to handle this better in some kind of re-usable user control or custom control

            if (btnOptions.ContextMenu != null)
            {
                btnOptions.ContextMenu.PlacementTarget = btnOptions;
                btnOptions.ContextMenu.IsOpen = true;
            }

            e.Handled = true;
            return;
        }
    }
}
